package com.woniuxy.joylifeshop.controller;

import com.woniuxy.common.entity.CenterUser;
import com.woniuxy.common.utils.JWTUtils;
import com.woniuxy.joylifeshop.exception.UserException;
import com.woniuxy.joylifeshop.service.CenterUserService;
import com.woniuxy.joylifeshop.vo.ResponseInformation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class UserController {

    @Autowired
    CenterUserService centerUserService;

    /**
    * @Author SooYoo
    * @Description 初始化中心
    * @Param
    * @Return
    **/
    @RequestMapping("/initInterface")
    public ResponseInformation initInterface(HttpServletRequest request){
        String userId = JWTUtils.getUserId(request.getHeader("token"));

        ResponseInformation responseInformation = new ResponseInformation();
        try {
            CenterUser centerUser = centerUserService.readUserByUserId(userId);

            responseInformation.setMsg("初始化成功");
            responseInformation.setState(200);
            responseInformation.setData(centerUser);

            return responseInformation;
        } catch (UserException e) {
            e.printStackTrace();

            responseInformation.setState(500);
            responseInformation.setMsg("初始化失败");

            return responseInformation;
        }

    }






}
